import requests
from pyquery import PyQuery as pq

url_fang = 'https://bj.fang.com/quanwangso/search.html?city=bj&refer=sy_seach'
response_fang = requests.get(url_fang)
doc_fang = pq(response_fang.text)

fang_categories = []
for category in doc_fang('#soCategory .tag > a'):
    name = pq(category).text().strip()
    url = pq(category).attr('href')
    fang_categories.append({
        'name': name,
        'url': url
    })

print('房天下分类：')
print(fang_categories)

url_guazi = 'https://www.guazi.com/bj/buy/'
response_guazi = requests.get(url_guazi)
doc_guazi = pq(response_guazi.text)

guazi_categories = []
for category in doc_guazi('.search_box .search_items li a'):
    name = pq(category).text().strip()
    url = pq(category).attr('href')
    guazi_categories.append({
        'name': name,
        'url': url
    })

print('\n瓜子二手车分类：')
print(guazi_categories)